var ReservationsInfoApp = {reservationsInfoData: {}, zTreeInstance: null, validateFields: {}};//初始化市场预约详情对话框
//清除数据
ReservationsInfoApp.clearData = function () {
    this.reservationsInfoData = {};
};
// 设置对话框中的数据 @param key 数据的名称 @param val 数据的具体值
ReservationsInfoApp.set = function (key, val) {
    this.reservationsInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
};
//设置对话框中的数据 @param key 数据的名称 @param val 数据的具体值
ReservationsInfoApp.get = function (key) {
    return $("#" + key).val();
};

//收集数据
ReservationsInfoApp.collectData = function () {
    this.set('customerName').set('customerSex').set('customerAge').set('customerPhone').set('statuss').set('appointmentPayService')
        .set('appointmentArrivalTime').set('accessDisease').set('outpatientName')
        .set('oneChannel').set('twoChannel').set('thrChannel').set('oneMedium').set('twoMedium').set('thrMedium')
        .set('remarks').set('userName').set('archiving');
};


//提交添加预约客户
ReservationsInfoApp.addSubmit = function (obj) {
    this.clearData();
    this.collectData();
    var appointmentPayService = $('#appointmentPayService').val();
    var customerSex = $("#customerSex").val();
    var customerName = $("#customerName").val(); //姓名
    var customerPhone = $("#customerPhone").val(); //电话
    var appointmentArrivalTime = $("#appointmentArrivalTime").val(); //预约时间
    var outpatientName = $("#outpatientName").val(); //门诊
    var oneChannel = $("#oneChannel").val();
    var twoChannel = $("#twoChannel").val();
    var thrChannel = $("#thrChannel").val();
    var accessDisease = $("#accessDisease").val();
    var statuss = $("#statuss").val();
    var remarks = $("#remarks").val();
    var customerAge = $("#customerAge").val();
    if (customerName == null || customerName == "") {
        alert("请输入姓名！");
        return;
    }
    if (customerPhone == null || customerPhone == "") {
        alert("请输入电话！");
        return;
    }
    if (customerPhone.length > 0 && customerPhone.length < 7 || customerPhone.length > 8 && customerPhone.length < 11) {
        alert("当前输入号码格式不对，请重新输入！");
        return;
    }
    if (statuss == null || statuss == "") {
        alert("请选择状态！");
        return;
    }
    if (appointmentPayService == null || appointmentPayService == "") {
        alert("请选择预约项目！");
        return;
    }
    if (appointmentArrivalTime == null || appointmentArrivalTime == "") {
        alert("请选择预约时间！");
        return;
    }
    if (outpatientName == null || outpatientName == "") {
        alert("请选择门诊！");
        return;
    }
    if (oneChannel == null || oneChannel == "请选择") {
        alert("请选择一级渠道！");
        return;
    }
    if (twoChannel == null || twoChannel == "请选择") {
        alert("请选择二级渠道！");
        return;
    }
    if (thrChannel == null || thrChannel == "请选择") {
        alert("请选择三级渠道！");
        return;
    }
    if (oneChannel != "直接上门" && accessDisease == "") {
        alert("请选择访问病种！");
        return;
    }
    if ($('#customerAge').val().length > 3) {
        alert("年龄长度应小于3")
        return;
    }
    if (remarks == null || remarks == "") {
        alert("填写客户详情！");
        return;
    }
    var ajax = new $ax(Feng.ctxPath + "/reservation/add", function (data) {
        if (data.split("#")[0] == 1) {
            if (obj == '1') {
                Feng.success("添加成功!");
                window.location.href = Feng.ctxPath + "/marketPatientsCentral/patient_query/market";
            }else {
                Feng.success("添加成功!");
                window.location.href = Feng.ctxPath + "/marketPatientsCentral/patient_query/market";
            }
        } else {
            alert("客户电话已存在");
        }
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.reservationsInfoData);
    ajax.start();
};


function checkDate() {
    var date = new Date();
    date.setDate(date.getDate() - 1);
    var now = date.valueOf();
    var time = new Date($("#appointmentArrivalTime").val()).valueOf();
    if (now > time) {
        layer.alert("预约时间不能小于当前时间！");
        $("#appointmentArrivalTime").val("")
    }
};


var oneChanneli = document.getElementById("oneChannelValue").value;
var twoChanneli = document.getElementById("twoChannelValue").value;
var thrChanneli = document.getElementById("thrChannelValue").value;
var ChannelList;
$.post(Feng.ctxPath + "/channel/getChannelssd", function (data) {
    ChannelList = data;
    channelInit('oneChannel', 'twoChannel', 'thrChannel');
}, "json");
$("#oneChannel").change(function () {
    setTimeout(function () {
        $("#oneMedium").val($("#oneChannel").val());
        $("#twoMedium").val($("#twoChannel").val());
        $("#thrMedium").val($("#thrChannel").val());
    }, 100)
});
$("#twoChannel").change(function () {
    setTimeout(function () {
        $("#oneMedium").val($("#oneChannel").val());
        $("#twoMedium").val($("#twoChannel").val());
        $("#thrMedium").val($("#thrChannel").val());
    }, 100)
});
$("#thrChannel").change(function () {
    setTimeout(function () {
        $("#oneMedium").val($("#oneChannel").val());
        $("#twoMedium").val($("#twoChannel").val());
        $("#thrMedium").val($("#thrChannel").val());
    }, 100)
});